package org.apache.struts2.plugin.json.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Definition of the JSON Array type.
 * @author VERDOÏA Laurent <verdoialaurent@gmail.com>
 */
public class JSONArray extends JSONValue<List<JSONValue>> {

    /**
     * Wrapper constructor for {@link JSONValue#JSONValue}
     * @see JSONValue#JSONValue
     */
    public JSONArray(List<JSONValue> data) {
        super(data);
    }

    /**
     * Wrapper constructor for {@link JSONValue#JSONValue(boolean)}
     * @see JSONValue#JSONValue
     */
    public JSONArray(boolean nullity) {
        super(nullity);
    }

    /**
     * Wrapper constructor for {@link JSONValue#JSONValue()}
     * @see JSONValue#JSONValue
     */
    public JSONArray() {
        super();
    }

    /**
     * Add data to Array. <br />
     * If the array is a null valued array. We create first an empty array.
     * @param data Data to add
     */
    public void addData(JSONValue data) {
        setNullity(false);
        this.data.add(data);
    }

    /**
     * @return <code>new ArrayList<JSONValue>()</code>
     */
    @Override
    protected List<JSONValue> instanciateData() {
        return new ArrayList<JSONValue>();
    }
}
